package org.cvcsc.weproject.service;

import org.cvcsc.weproject.controller.dto.RequestDtoInsertClazz;
import org.cvcsc.weproject.domain.Clazz;
import org.cvcsc.weproject.repository.ClazzRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Service
public class ClazzService {
    @Autowired
    private ClazzRepository clazzRepository;

    public void removeAllClazzes() {
        clazzRepository.deleteAll();
    }

    public List<Long> saveClazzes(List<RequestDtoInsertClazz> clazzes) { // 修改方法签名
        List<Clazz> clazzlist=clazzes.stream().map(clazz -> Clazz.instanceOf(clazz.getName(), clazz.getNumber())).collect(Collectors.toList());
        clazzlist = clazzRepository.saveAll(clazzlist);
        return clazzlist.stream().map(Clazz::getId).collect(Collectors.toList());
    }
}